package avicit.bdp.dms.tdm.rest;

import avicit.bdp.dms.tdm.dto.AssetLogDTO;
import avicit.bdp.dms.tdm.service.AssetLogService;
import avicit.platform6.core.rest.msg.QueryRespBean;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @金航数码科技有限责任公司
 * @作者：${tableInfo.classCreator}
 * @邮箱：${tableInfo.classMailbox}
 * @创建时间： 2023-11-14 16:03
 * @类说明：bdp_asset_logRest
 * @修改记录：
 */
@RestController
@Api(tags = "数据资产访问日志")
@RequestMapping("/api/bdp/dms/asset/log")
public class AssetLogRest {

    private static final Logger logger = LoggerFactory.getLogger(AssetLogRest.class);

    @Autowired
    private AssetLogService assetLogService;

    @ApiOperation(value = "分页查询资产使用日志")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "资产ID", name = "assetId", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "调用人ID", name = "callUserId", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "当前页", name = "pageNo", dataType = "Int", paramType = "query"),
            @ApiImplicitParam(value = "每页大小", name = "pageSize", dataType = "Int", paramType = "query")
    })
    @GetMapping("/getAssetLogPageList")
    public ResponseMsg<QueryRespBean<AssetLogDTO>> getAssetLogPageList(
            @RequestParam String assetId,
            @RequestParam(required = false) String callUserId,
            @RequestParam(defaultValue = "1") Integer pageNo,
            @RequestParam(defaultValue = "10") Integer pageSize) throws Exception {
        ResponseMsg<QueryRespBean<AssetLogDTO>> responseMsg = new ResponseMsg<>();
        QueryRespBean<AssetLogDTO> result = assetLogService.getAssetLogPageList(assetId, callUserId, pageNo, pageSize);
        responseMsg.setResponseBody(result);
        return responseMsg;
    }

    @ApiOperation(value = "新增")
    @PostMapping("/save")
    public ResponseMsg<String> save(@RequestBody AssetLogDTO dto) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(assetLogService.save(dto));
        return responseMsg;
    }

    @ApiOperation(value = "通过ID查询")
    @ApiParam(value = "id", name = "id", required = true)
    @GetMapping("/{id}")
    public ResponseMsg<AssetLogDTO> queryById(@PathVariable String id) {
        ResponseMsg<AssetLogDTO> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(assetLogService.queryById(id));
        return responseMsg;
    }

    @ApiOperation(value = "资产监控概览")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "时间类型", name = "timeType", dataType = "String", paramType = "query")
    })
    @GetMapping("/overview")
    public ResponseMsg<Map<String, Object>> overview(
            @RequestParam(required = false) String timeType) throws Exception {
        ResponseMsg<Map<String, Object>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(assetLogService.overview(timeType));
        return responseMsg;
    }

}